﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;
using ITProject.Domain.Entities;

namespace ITProject.WebUI.Models.ProjectTeamLeader
{
    public class ProjectTeamLeaderAddTeamTaskViewModel
    {
        [Display(Name = "Nazwa")]
        [Required(ErrorMessage = "Nazwa zadania jest wymagana")]
        [MinLength(4, ErrorMessage = "Nazwa zadania musi posiadać conajmniej 4 znaki")]
        [MaxLength(50, ErrorMessage = "Nazwa zadania nie może posiadać więcej niż 50 znaków")]
        public string Name { get; set; }
        [Display(Name = "Opis")]
        public string Description { get; set; }
        [Display(Name = "Planowana data ukończenia zadania")]
        [Required(ErrorMessage = "Podanie planowanej daty ukończenia jest wymagane")]
        public DateTime PlannedEndDate { get; set; }
        [Required(ErrorMessage = "Musisz podać status zadania")]
        [Display(Name = "Status zadania")]
        public string ReturnStatus { get; set; }
        [Display(Name = "Priorytet")]
        [Required(ErrorMessage = "Musisz wybrać priorytet zadania")]
        public string ReturnPriority { get; set; }
        [Display(Name = "Uczestnik odpowiedzialny za zadanie")]
        [Required(ErrorMessage = "Musisz wybrać uczestnika odpowiedzialnego za zadanie")]
        public string ReturnUser { get; set; }
        [Display(Name = "Przypisanie do funkcjonalności")]
        [Required(ErrorMessage = "Musisz przypisac funkcjonalność do zadania")]
        public string ReturnFeature { get; set; }

        //ustawiane przez kontroler i ukryte
        public string ProjectName { get; set; }
        public int TeamId { get; set; }

        public static List<SelectListItem> StatusList;
        public PriorityViewModel PriorityList
        {
            get { return pvm; }
        }
        public List<SelectListItem> FeatureList;
        public List<SelectListItem> UserList;

        private PriorityViewModel pvm = new PriorityViewModel();
        
        static ProjectTeamLeaderAddTeamTaskViewModel()
        {
            StatusList = new List<SelectListItem>();
            StatusList.Add(new SelectListItem { Text = StatusName.Active });
            StatusList.Add(new SelectListItem { Text = StatusName.Planned });
            StatusList.Add(new SelectListItem { Text = StatusName.Done });
            StatusList.Add(new SelectListItem { Text = StatusName.Tested });
            StatusList.Add(new SelectListItem { Text = StatusName.Accepted });
        }

        public static Task Convert(ProjectTeamLeaderAddTeamTaskViewModel vm, int projectId, int userId, int featureId)
        {
            Task task = new Task();
            task.Name = vm.Name;
            task.PlannedStopDate = vm.PlannedEndDate;
            task.Priority = (byte)PriorityViewModel.ConvertFromString(vm.ReturnPriority);
            task.ProjectId = projectId;
            task.FeatureId = featureId;
            task.StartDate = DateTime.Now;
            task.Status = (byte)StatusName.ConvertFromString(vm.ReturnStatus);
            task.UserId = userId;
            task.Description = vm.Description;
            return task;
        }
    }
}